<?php

namespace PlatBundle\Controller;

use ApiBundle\Controller\BaseController;

class SettingController extends BaseController
{

    /*
     * 个人信息
     */
    public function indexAction()
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAssoc("SELECT * FROM admin WHERE id = '". $this->get("session")->get("plat_id") ."' AND admin_role_id = 1");
        return $this->render("PlatBundle:Setting:index.html.twig",array("data"=>$data));

    }


    /*
     * 完善个人信息
     */
    public function editSelfMessageAction()
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }
        $conn = $this->get("database_connection");
        $data = $conn->fetchAssoc("SELECT * FROM admin WHERE id = '". $this->get("session")->get("plat_id") ."' AND admin_role_id = 1");
        return $this->render("PlatBundle:Setting:editInformation.html.twig",array("data"=>$data));

    }

    /*
     * 修改密码
     */
    public function updatePasswordAction()
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }
        return $this->render("PlatBundle:Setting:editPassword.html.twig");
    }

    /*
     * 获取超链接
     */

    public function getLinkAction()
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }
        return $this->render("PlatBundle:Setting:editLink.html.twig");
    }

    /*
     * banner列表
     */
    public function bannerListAction()
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }
        return $this->render("PlatBundle:Setting:bannerList.html.twig");
    }

    /*
     * 编辑banner
     */

    public function editBannerAction($id)
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAssoc("SELECT * FROM banner WHERE id = '". $id ."'");

        if(empty($id)){
            $data = array("id"=>$id);
        }

        return $this->render("PlatBundle:Setting:editBanner.html.twig",array("data"=>$data));
    }
}
